clc
clear
close all                              
%被测信号频率
f1 = 40;
f2 =1546.5;
f3 =40*64;
% 点数
N = 8192;
% 采样率
% Fs = 6553.6
% Fs = f3*32
Fs = f2*32
% Fs = f1*N/8;
%采样间隔时间
T = 1/Fs;
%分辨率
Fbl = Fs/N;
%设置采样 采样总时间：N*Ts  采N个点
x = linspace(0,N*T,N);
%进行采样
% y = sin(2*pi*f1*x)+0.1*sin(2*pi*f2*x)+0.01*sin(2*pi*f3*x);%带两个谐波
y = sin(2*pi*f1*x)+0.1*sin(2*pi*f2*x);%只带一个谐波
%  y = sin(2*pi*f1*x);
figure
plot(x,y,'r');
%进行FFT
Y = fft(y);
%取单边图谱
P2 = abs(Y)/N*2;
P1 = P2(1:N/2+1);
% P1(1:1) = P1(1:1)/2;%直流部分不需要乘2
k = Fs/N*(0:(N/2));
%得到的横坐标为频点，纵坐标为幅度
figure
plot(k,P1);
